package fr.axones.pocketagile.vo
{
	import flash.utils.ByteArray;
	
	import mx.collections.ArrayCollection;

	[RemoteClass]
	public class UserVO
	{
		public var id:Number;
		public var displayName:String;
		
		public var email:String;
		public var password:String;
		
		public var profile:String;
		
		public static const PROFILE_ADMIN:String = "Admin";
		public static const PROFILE_PRODUCT_OWNER:String = "Product owner";
		public static const PROFILE_SCRUM_MASTER:String = "Scrum master";
		public static const PROFILE_DEVELOPER:String = "Developer";
		public static const PROFILE_USER:String = "User";
		
		public function UserVO()
		{
		}
		
		public static function builds(a:Array):ArrayCollection
		{
			var ac:ArrayCollection = new ArrayCollection();
			
			for each(var o:Object in a)
			{
				ac.addItem(buildObject(o));
			}			
			
			return ac;
		}
		
		public static function build(s:String):UserVO
		{
			var o:Object = JSON.parse(s);
			
			return buildObject(o);
		}
		
		public static function buildObject(o:Object):UserVO
		{
			var user:UserVO = new UserVO();
			
			for (var propertyName:String in o){
				user[propertyName] = o[propertyName];
			}
			
			return user;
		}
		
		public function clone():UserVO
		{
			var buffer:ByteArray = new ByteArray();
			buffer.writeObject(this);
			buffer.position = 0;
			return buffer.readObject();
		}
	}
}